package com.tledu.production.controller.common;

import com.tledu.production.constant.SessionConstant;
import com.tledu.production.model.crafts.ProcessModel;
import com.tledu.production.model.crafts.TechnologyModel;
import com.tledu.production.model.crafts.TechnologyPlanModel;
import com.tledu.production.model.crafts.TechnologyRequirementModel;
import com.tledu.production.service.crafts.ITechnologyPlanService;
import com.tledu.production.service.crafts.ITechnologyReallyPlanService;
import com.tledu.production.service.crafts.ITechnologyService;
import com.tledu.production.service.crafts.ProcessService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Antg
 * @date 2021/8/17  19:33
 */
@Controller
@AllArgsConstructor
public class CommonCraftsController {
    /***************************** 工艺监控 ***********************************/
   /*
   工艺管理
    */
    private ITechnologyService technologyService;
    private ITechnologyReallyPlanService technologyReallyPlanService;
    private ITechnologyPlanService technologyPlanService;
    private ProcessService processService;
    //分页查询
    @GetMapping("/crafts/technology-list")
    public String goTechnologyList(HttpSession session){
        return "crafts/technology-list";

    }
    //搜索
    //添加
    @GetMapping("/crafts/technology-add")
    public String goTechnologyAdd(){
        return "crafts/technology-add";
    }
    //编辑
    @GetMapping("/crafts/technology-edit")
    public String goTechnologyEdit(String technologyId, HttpSession session){
        TechnologyModel technologyModel = technologyService.findById(technologyId);
        if (technologyModel == null) {
            return "error/error";
        }
        session.setAttribute("tec",technologyModel);
        return "crafts/technology-edit";
    }
    /*
    工艺要求
     */
    //分页/搜索
    @GetMapping("/crafts/technologyPlan-list")
    public String goTechnologyPlanList(){return "crafts/technologyPlan-list";}
    //增加
    @GetMapping("/crafts/technologyPlan-add")
    public String goTechnologyPlanAdd(Model model) {
        List<TechnologyModel> cloud = technologyService.cloud();
        model.addAttribute("cloud",cloud);
        return "crafts/technologyPlan-add";
    }
    //编辑
    @GetMapping("/crafts/technologyPlan-edit")
    public String goPlanEdit(Model model, String technologyRequirementId){
        List<TechnologyModel> cloud = technologyService.cloud();
        model.addAttribute("cloud",cloud);
        TechnologyRequirementModel ment = technologyPlanService.selectRe1Id(technologyRequirementId);
        model.addAttribute("ment",ment);
        String text = technologyPlanService.finfEdit(technologyRequirementId);
        model.addAttribute("editText",text);
        return "crafts/technologyPlan-edit";
    }
    /*
    工艺计划
     */
    //分页查询
    @GetMapping("/crafts/technologyReally-list")
    public String goTechnologyReallyList(){
        return "crafts/technologyReally-list";
    }
    //增加
    @GetMapping("/crafts/technologyReally-add")
    public String goTechnologyReallyAdd(Model model) {
        List<TechnologyModel> cloud = technologyService.cloud();
        model.addAttribute("cloud",cloud);
        return "crafts/technologyReally-add";
    }
    //编辑
    @GetMapping("/crafts/technologyReally-edit")
    public String goReallyEdit(Model model,String technologyPlanId){
        List<TechnologyModel> cloud = technologyService.cloud();
        model.addAttribute("cloud",cloud);
        TechnologyPlanModel ment = technologyReallyPlanService.select(technologyPlanId);
        model.addAttribute("ment",ment);
        return "crafts/technologyReally-edit";
    }
    /*
    工序管理
     */
    //分页
    @GetMapping("/crafts/process-list")
    public String goProcessList(){
        return "crafts/process-list";
    }
    //增加
    @GetMapping("/crafts/process-add")
    public String goProcessAdd(Model model) {
        List<TechnologyPlanModel> cloud = technologyReallyPlanService.list();
        model.addAttribute("cloud",cloud);
        return "crafts/process-add";
    }
    //编辑
    @GetMapping("/crafts/process-edit")
    public String goProcessEdit(String processId,Model model){
        List<TechnologyPlanModel> cloud = technologyReallyPlanService.list();
        model.addAttribute("cloud",cloud);
        ProcessModel req = processService.selectId(processId);
        model.addAttribute("req",req);
        return "crafts/process-edit";
    }

}
